import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Animation Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: AnimationPage(),
    );
  }
}

class AnimationPage extends StatefulWidget {
  @override
  _AnimationPageState createState() => _AnimationPageState();
}

class _AnimationPageState extends State<AnimationPage> with SingleTickerProviderStateMixin {
  late AnimationController _controller;
  late Animation<double> _animation;
  late Animation<Color?> _colorAnimation;
  late CurvedAnimation _curve;

  @override
  void initState() {
    super.initState();

    // 初始化动画控制器
    _controller = AnimationController(
      duration: const Duration(seconds: 2),
      vsync: this,
    );

    // 创建动画曲线
    _curve = CurvedAnimation(parent: _controller, curve: Curves.easeInOut);

    // 创建动画
    _animation = Tween(begin: 0.0, end: 1.0).animate(_curve);

    // 创建颜色动画
    _colorAnimation = ColorTween(begin: Colors.blue, end: Colors.red).animate(_curve);

    // 启动动画
    _controller.forward();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Animation Demo'),
      ),
      body: Center(
        child: AnimatedBuilder(
          animation: _animation,
          builder: ( context,  child) {
            return Container(
              width: 200.0 * _animation.value,
              height: 200.0 * _animation.value,
              color: _colorAnimation.value,
            );
          },
        ),
      ),
    );
  }
}
